﻿using WebServiceMGI;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ComunesMGI.DataTypes;
using System.Collections.Generic;
using System;

namespace TestWebServiceMGI
{
    
    
    /// <summary>
    ///This is a test class for IMGIClientesSistemasWSTest and is intended
    ///to contain all IMGIClientesSistemasWSTest Unit Tests
    ///</summary>
    [TestClass()]
    public class IMGIClientesSistemasWSTest
    {

        private DataCliente cli;

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion
        internal virtual IMGIClientesSistemasWS CreateIMGIClientesSistemasWS()
        {
            // TODO: Instantiate an appropriate concrete class.
            IMGIClientesSistemasWS target = new MGIClientesSistemasWS();
            return target;
        }

        /// <summary>
        ///A test for GetSistemas
        ///</summary>
        [TestMethod()]
        public void GetSistemasTest()
        {
            IMGIClientesSistemasWS target = CreateIMGIClientesSistemasWS(); 
            int cliCod = 1;
            List<DataSistema> expected = new List<DataSistema>();
            expected.Add(new DataSistema("IC-Banking", "http://localhost/pis2008/mgi", cliCod, "http://localhost:9000/"));
            List<DataSistema> actual;
            actual = target.GetSistemas(cliCod);
            CollectionAssert.Equals(expected, actual);
        }

        /// <summary>
        ///A test for GetClientes
        ///</summary>
        [TestMethod()]
        public void GetClientesTest()
        {
            IMGIClientesSistemasWS target = CreateIMGIClientesSistemasWS();
            List<DataCliente> expected = new List<DataCliente>();
            expected.Add(new DataCliente("BSCH"));
            List<DataCliente> actual;
            actual = target.GetClientes();
            CollectionAssert.Equals(expected, actual);
        }



        /// <summary>
        ///A test for AddCliente
        ///</summary>
        [TestMethod()]
        public void AddClienteTest()
        {
            try
            {
                IMGIClientesSistemasWS target = CreateIMGIClientesSistemasWS(); 
                cli = new DataCliente("cliente1"); 
                int idCliente = target.AddCliente(cli);
                List<DataCliente> clientes = target.GetClientes();
                CollectionAssert.Contains(clientes, cli);
            }
            catch (Exception e)
            {
                Console.WriteLine(  e.Message);
                Assert.Fail(); 
            }
        }

        

        /// <summary>
        ///A test for BajaCliente
        ///</summary>
        [TestMethod()]
        public void BajaClienteTest()
        {
           
            IMGIClientesSistemasWS target = CreateIMGIClientesSistemasWS();       
            target.BajaCliente(2);
            List<DataCliente> clientes = target.GetClientes();
            CollectionAssert.DoesNotContain(clientes,cli);
        }



        /// <summary>
        ///A test for ModificarCliente
        ///</summary>
        [TestMethod()]
        public void ModificarClienteTest()
        {
            IMGIClientesSistemasWS target = CreateIMGIClientesSistemasWS(); 
            DataCliente cli = new DataCliente("Lucia");
            target.AddCliente(cli);
            DataCliente cliNuevo = new DataCliente(cli.Codigo, "Gabriel");
            target.ModificarCliente(cliNuevo);
            List<DataCliente> clientes = target.GetClientes();
            bool contieneModificado = clientes.Contains(cliNuevo);
            bool contieneViejo = clientes.Contains(cli);
            Assert.IsTrue( contieneModificado && !contieneViejo);
            target.BajaCliente(cli.Codigo);
        }

        /// <summary>
        ///A test for AddSistema
        ///</summary>
        [TestMethod()]
        public void AddSistemaTest()
        {
            IMGIClientesSistemasWS target = CreateIMGIClientesSistemasWS();
            DataSistema sistema = new DataSistema(2,"SistemaLucia", "SitioLucia", 1, "url");
            target.AddSistema(sistema);
            List<DataSistema> sistemas = target.GetSistemas(1);
            CollectionAssert.Contains(sistemas, sistema);
            
        }

        /// <summary>
        ///A test for ModificarSistema
        ///</summary>
        [TestMethod()]
        public void ModificarSistemaTest()
        {
            IMGIClientesSistemasWS target = CreateIMGIClientesSistemasWS();
            DataSistema sistema = new DataSistema(2, "SsitemaMagda", "SitioMagda", 1, "url");
            target.ModificarSistema(sistema);
            List<DataSistema> sistemas = target.GetSistemas(1);
            CollectionAssert.Contains(sistemas, sistema);
        }

        /// <summary>
        ///A test for BajaSistema
        ///</summary>
        [TestMethod()]
        public void BajaSistemaTest()
        {
            IMGIClientesSistemasWS target = CreateIMGIClientesSistemasWS();
            int sisCod = 2;
            DataSistema sistema = new DataSistema(2, "SsitemaMagda", "SitioMagda", 1, "url");
            target.BajaSistema(sisCod);
            List<DataSistema> sistemas = target.GetSistemas(1);
            CollectionAssert.DoesNotContain(sistemas, sistema);
        }
    }
}
